package com.sync.syncmasterdata;


import com.fasterxml.jackson.databind.ObjectMapper;
import com.sync.syncmasterdata.customer.controller.CusSyncController;
import com.sync.syncmasterdata.dingrobot.controller.DingController;
import com.sync.syncmasterdata.dingrobot.pojo.DingMsg;
import com.sync.syncmasterdata.product.entity.wms.EleProduct;
import com.sync.syncmasterdata.product.pojo.cp.InventoryForCP;
import com.sync.syncmasterdata.product.pojo.oa.InventoryForOA;
import com.sync.syncmasterdata.product.service.SyncInventoryService;
import com.sync.syncmasterdata.product.service.convert.ProductOAtoCP;
import com.sync.syncmasterdata.product.service.convert.ProductOAtoWms;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.json.JSONException;
import org.json.JSONObject;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.web.client.RestTemplate;

import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@SpringBootTest
@Slf4j
class SyncMasterDataApplicationTests4 {

    @Autowired
    private ObjectMapper objectMapper;

    @Autowired
    private SyncInventoryService syncInventoryService;

    @Test
    public void test1(){
        InventoryForCP cp = new InventoryForCP();
        cp.setCunhuobm("Test111");
        cp.setChanpinmc("Test123333");
        cp.setHuohao("setHuohao");
        cp.setGuigexh("setGuigexh");
        cp.setPinpaiwb("setPinpaiwb");

        try {
            RestTemplate restTemplate = new RestTemplate();
            //中文乱码问题
            restTemplate.getMessageConverters().set(1,new StringHttpMessageConverter(StandardCharsets.UTF_8));
            HttpHeaders headers = new HttpHeaders();
            headers.setContentType(MediaType.APPLICATION_JSON);
            headers.set("schemaCode","chanpinbjwh");
            JSONObject reqJson = new JSONObject();
            reqJson.put("id", "123");
            reqJson.put("huohao", cp.getHuohao());
            reqJson.put("guige", cp.getGuigexh());
            reqJson.put("pinpai", cp.getPinpaiwb());
            reqJson.put("chanpinmc", cp.getChanpinmc());
            reqJson.put("cunhuobm", cp.getCunhuobm());
            String requestUrl2=String.format("%s%s","http://127.0.0.1:8080/api","/api/presale/customiz/backEnd/standardGroup/updateStandardGroupProduct");
            HttpEntity<String> reqEntity2 = new HttpEntity<>(reqJson.toString(), headers);
            String ret=restTemplate.postForObject(requestUrl2, reqEntity2, String.class);
        } catch (JSONException e) {
            throw new RuntimeException(e);
        }

    }
}
